decorative banner

Shutdown & Startup


    Within the Scripts folder are two subfolders called "Startup" and "Shutdown." After Effects runs scripts in these folders automatically on starting and quitting the application, respectively.

    In the Startup folder you can place scripts that you wish to execute at startup of the application. They are executed after the application is initialized and all plug-ins are loaded.

    Scripting shares a global environment, so any script executed at startup can define functions and properties that are available to all scripts. Defining a function in a startup script will make it available to all other scripts. In other words, variables and functions, once defined by running a script which contains them, persist in succeeding scripts.

    Please note that this persistence of global settings also means that if you are not careful about giving variables in scripts unique names, you can inadvertently reassign global variables intended to persist throughout a session.

    Properties can also be embedded in existing objects such as the Application object (see Application Object) to extend the application for other scripts.

    The Shutdown folder scripts are executed as the application quits. This occurs after the project is closed, but before any other application shutdown occurs.

Editing scripts (Windows)

    You can use any text editor to create, edit and save scripts, but it is recommended that you choose an application that saves with UTF-8 encoding and does not add its own headers.

    Windows applications that are useful for editing scripts include EM Editor or the built-in Windows Notepad (be sure to set Encoding within save options to UTF-8).

Editing scripts (Mac)

    You can use any text editor to create, edit and save scripts, but it is recommended that you choose an application that does not automatically add header information when saving files, as Microsoft Word does, and which saves with Unicode (UTF-8) encoding.

    Mac applications that are useful for editing scripts include BBEdit or the built-in OS X Textedit (be sure to set the Save type in Preferences to Unicode [UTF-8]).

Sending a script to After Effects from the system

    If you are familiar with how to run a script from the command line in Windows or via AppleScript, you can send a script directly to the open After Effects application which will then run automatically.

To include After Effects scripting in an AppleScript (Mac only):

    Following are three examples of AppleScripts that will send an existing .jsx file containing an After Effects script to the application without using the After Effects user interface to execute the script.

    In the first example, you copy your After Effects script directly into the AppleScript and then run it, as follows (your script text would appear in quotes following the DoScript command):

    tell application " Adobe After Effects 6.0"
        DoScript "alert (\"You just sent an alert to After Effects\")"
    end tell

    Alternatively, you could pop up a dialog asking for the location of the .jsx file to be executed, as follows:

    set thefile to choose file
    tell application "Adobe After Effects 6.0"
        DoScript thefile
    end tell

    Finally, this script is perhaps most useful when you are working directly on editing a .jsx script and want to send it to After Effects for testing or to run. To use it effectively you must enter the application that contains the open .jsx file (in this example it is TextEdit); if you do not know the proper name of the application, type in your best guess to replace "TextEdit" and AppleScript will prompt you to locate it.

    Simply highlight the script text that you want to run, and then activate this AppleScript:

    (*
    This script sends the current selection to After Effects as a script.
    *)
    tell application "TextEdit"
       
        set the_script to selection as text
       
    end tell
    tell application "Adobe After Effects 6.0"
        activate
        DoScript the_script
    end tell

    For more information on using AppleScript, check out David Pogue's Mac OS X, the Missing Manual (Pogue Press/O'Reilly) or Ethan Wilde's AppleScript for Applications (Peachpit Press).